<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use Illuminate\Database\Eloquent\Model;

class CaseCustomer extends Model
{
    use HasDateTimeFormatter, HasRelationships;
    protected $table = 'case_customers';
    protected $fillable = ['admin_user_id','batch_count'];
    public function caseContacts()
    {
        return $this->hasMany(CaseContact::class);
    }

    public function caseContracts()
    {
        return $this->hasMany(CaseContract::class);
    }


    public function caseCases()
    {
        return $this->hasManyDeep(CaseCase::class, [CaseContract::class, CaseBatch::class]);
    }

    public function adminUser()
    {
        return $this->belongsTo(AdminUser::class);
    }

    public function caseEvents()
    {
        return $this->hasMany(CaseEvent::class);
    }
    public function attachments()
    {
        return $this->hasMany(Attachment::class);
    }

    public function caseOpportunitys()
    {
        return $this->hasMany(CaseOpportunity::class);
    }

    public function sharesUser()
    {
        return $this->belongsToMany(AdminUser::class, 'case_shares', 'case_customer_id', 'user_id');
    }

    public function caseBatchs()
    {
        return $this->hasManyThrough(CaseBatch::class, CaseContract::class);
    }
}
